
<div class="row">
    <div class="container-fluid">
        <div class="col-lg-12 no-padding">
            <section class="content-header">
                <ol class="breadcrumb">
                    <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
                    <li><a href="#" class="active">我的上传</a></li>
                </ol>
            </section>
            <!-- Main content -->
            <section class="content">
                <div class="row">
                    <div class="col-lg-12 no-padding">
                        <div class="jax-box jax-box-table">
                            <div class="jax-box jax-box-table">
                                <div id="toolbar">
                                    <div class="btn-group">
                                        <shiro:hasPermission name="download_my">
                                        <a id="btn_batch_download_immediately_my" class="btn btn-success">
                                            <i class="fa fa-download"></i>
                                            批量下载
                                        </a>
                                        </shiro:hasPermission>
                                    </div>
                                </div>
                            <table id="table" class="table table-striped">
                            </table>
                        </div>
                    </div>
                </div>
                </div>
            </section>

            <!-- 文件详情模态框 -->
            <div id="fileInDetailfoModal" class="modal fade " tabindex="-1" role="dialog">
                <div class="modal-dialog modal-lg" role="document">
                    <div class="modal-content">
                        <div class="modal-body">
                            <div class="box box-widget">
                                <div class="box-header with-border">
                                    <div>
                                       <!-- <div>
                                            <span id="fileNumber">ID: 8888</span>&nbsp;&nbsp;
                                        </div>-->
                                        <h3 class="pull-left">
                                            <span id="fileName4Details">java web开发课程大纲.zip</span>&nbsp;&nbsp;
                                        </h3>
                                    </div>
                                    <!-- /.user-block -->
                                    <div class="box-tools">
                                        <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                                        </button>
                                        <button type="button" class="btn btn-box-tool" data-dismiss="modal" aria-label="Close"><i class="fa fa-times"></i></button>
                                    </div>
                                    <!-- /.box-tools -->
                                </div>


                                <!-- /.box-header -->
                                <div class="box-body">
                                    <div class="attachment-block clearfix">
                                        <dl>
                                            <dt>关键说明:</dt>
                                            <dd>&nbsp;&nbsp;&nbsp;&nbsp;<span id="fileKeys4Details"></span></dd>
                                            <dt>类别:</dt>
                                            <dd>&nbsp;&nbsp;&nbsp;&nbsp;<span id="categoryName4Details"></span></dd>
                                            <dt>提供者:</dt>
                                            <dd>&nbsp;&nbsp;&nbsp;&nbsp;<span id="creatorName4Details"></span></dd>
                                        </dl>
                                    </div>

                                        <dl>
                                            <dd>
                                                <p id="detail4Details">
                                                </p>
                                            </dd>
                                        </dl>

                                    <!-- Social sharing buttons -->

                                </div>
                                <!-- /.box-body -->


                            </div>
                        </div>
                    </div>
                </div>
            </div>


            <!-- 编辑文件 模态框 -->
            <div id="fileInfoUpdateModal" class="modal fade" tabindex="-2" role="dialog">
                <div class="modal-dialog modal-lg" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title">编辑文件</h4>
                        </div>
                        <div class="modal-body">
                            <div id="formDiv">

                            </div>
                        </div>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal-dialog -->
            </div>

            <div id="categoryLayer" style="display: none;padding-left: 20px;">
                <ul id="categoryTree" class="ztree"></ul>
            </div>

        </div>
    </div>
</div>
<script>

    /* * *权限标识 */
    var downloadMyFlag = "[[${@perms.hasPerm('download_my')}]]";//下载我的文件
    var fileInfoEditMy = "[[${@perms.hasPerm('fileinfo:editMy')}]]";//编辑我的文件
    var fileInfoDeleteMy = "[[${@perms.hasPerm('fileinfo:deleteMy')}]]";//删除我的文件

    /* // 查询、表格 Start*/
    $(function () {
        window.operateEvents  = {
            'click .show_detail': function (e, value, row, index) {
                $("#fileInDetailfoModal").modal("show");
                $("#fileNumber").html("ID: "+row.fileNumber);
                $("#fileName4Details").html(row.fileName);
                $("#fileKeys4Details").html(row.fileKeys);
                $("#categoryName4Details").html(row.categoryName);
                $("#creatorName4Details").html(row.creatorName);
                $("#detail4Details").html((row.detail||"无详细说明"));
             },
            // 更改操作的方法
            'click .btn_edit': function (e, value, row, index) {
                let id = row.id;
                Core.postAjax("/fileInfo/edit_my",{id:id},function (data) {
                    $("#formDiv").html(data);
                    $('#detail_edit').wysihtml5({
                        toolbar: {
                            "font-styles": true,// Font styling,e.g. h1,h2,etc.
                            "emphasis": true,// Italics,bold,etc.
                            "lists": true,// (Un)ordered lists,e.g. Bullets,Numbers.
                            "html": true,// Button which allows you to edit the generated HTML.
                            "link": false,// Button to insert a link.
                            "image": false,// Button to insert an image.
                            "color": false,// Button to change color of font
                            "blockquote": true,// Blockquote
                            "size": "sm" // options are xs,sm,lg
                        }
                    } );
                    $("#fileInfoUpdateModal").modal("show");
                },"get");
            },
            //删除自己的文件 单行/
            'click .btn_del': function (e, value, row, index) {
                let id = row.id;
                Core.confirm("请确认删除：【"+row.fileName+"】",function () {
                   Core.postAjax("/fileInfo/delete-myfileinfo/",JSON.stringify({"id":id}),function (data) {
                        if(data["data"]){
                            layer.msg("操作成功")
                            Core.refreshTable("#table");
                        }else {
                            layer.msg(data["msg"]);
                        }
                   },"delete","application/json");
                })
            },

            //下载 单行/
           'click .btn_downloadOne_immediately_my': function (e, value, row, index) {
               let id = row.id;
               Core.confirm('下载:'+row.fileName,function () {
                   let ids =[id];
                   layer.msg("正在处理文件",{time:1000},function () {
                       Core.postAjax("/download/download_my",JSON.stringify(ids),function (data) {
                           Core.refreshTable("#table");
                           if(data["data"]){
                               $("<form></form>").attr("action", "/download/"+data["data"]).attr("method","post").appendTo('body').submit().remove();
                           }else {
                               layer.msg("服务器异常");
                           }
                       },"post","application/json");
                   })
               });
            }
        };
        $("#btn_batch_download_immediately_my").click(function(){
            var checkedRows= Core.selectMutiData("#table");
            if(checkedRows){
                Core.confirm('下载文件数量:'+checkedRows.length,function () {
                    let ids =[];
                    $.each(checkedRows, function (i, item) {
                        ids.push(item.id);
                    });
                    layer.msg("正在处理文件",{time:1000},function () {
                        Core.postAjax("/download/download_my",JSON.stringify(ids),function (data) {
                            Core.refreshTable("#table");
                            if(data["data"]){
                                $("<form></form>").attr("action", "/download/"+data["data"]).attr("method", "post").appendTo('body').submit().remove();
                            }else {
                                layer.msg("服务器异常");
                            }
                        },"post","application/json");
                    })
                });
            }
        });

        let columns = [
            {checkbox: true ,
                field : 'checked'},
           /* {
                field: 'fileNumber',
                title: '文件ID',
                width:80,
                align:"center"

            },*/
            {
                field: 'fileName',
                title: '文件名',
                formatter:function (value, row, index) {
                    var icon = "<i class='fa "+row.fileIcon+"' style='font-size: 20px;'></i>&nbsp;&nbsp;";
                    if(value.length>31){
                        return icon+ ' <a href="javascript:void(0)" class="show_detail" ' +
                            'data-toggle="tooltip" data-placement="top" title="' +value+
                            '">'+(value.substring(0, 25)+"......"+value.substring(value.length-6))+'</a>';
                    }else{
                        return icon+' <a href="javascript:void(0)" class="show_detail" ' +
                            '">'+value+'</a>';
                    }
                },
                fixed:true,
                events: window.operateEvents
            },
            {
                field: 'categoryName',
                title: '类别'

            },
            {
                field: 'creatorName',
                title: '提供者',
                width:100,
                align: 'center',
            },
            {
                field: 'createtime',
                title: '上传时间'
                ,width:100
                , align: 'center'
            },
            {
                title: '操作',
                width: 200,
                align: 'center',
                formatter:function (value, row, index) {
                    var downloadImmediately = (downloadMyFlag=="true"?'<a  class="table-btn table-btn-success btn_downloadOne_immediately_my" href="javascript:void(0)"><i class="fa fa-fw fa-download"></i>下载</a> ':"");
                    var edit = (fileInfoEditMy=="true"?'<a class="table-btn table-btn-info btn_edit" href="javascript:void(0)">编辑</a>':"");
                    var del = (fileInfoDeleteMy=="true"?'<a  class="table-btn table-btn-danger btn_del" href="javascript:void(0)">删除</a>':"");
                    return downloadImmediately+edit + del;
                },
                events:window.operateEvents
            }

        ];
        let options={
            id:"#table",
            url: '/fileInfo/list-myupload',
            method:'get',
            columns:columns,
            showRefresh: true,
            toolbar: '#toolbar',
          //  sortable:true,
            pageList: "[10, 25, 50, 100, all]",
            queryParams : queryParams
        }
        Core.initTable(options);

        /*查询参数*/
        function queryParams(params) {
            return {
                limit : params.limit, //页面大小
                pageNo : (params.offset/params.limit)+1, //页码
            };
        }
    });
    /* // 查询、表格 End */


    /* 确定提交更改的事件*/
    $("#fileInfoUpdateModal").on("click","#save_EditFileInfo",function () {
        $.ajax({
            url : "fileInfo/edit_submit",
            type : 'POST',
            cache : false,
            data : new FormData($('#editForm')[0]),
            processData : false,
            contentType : false,
            success : function(data) {
                if(data["status"]==200){
                    $("#fileInfoUpdateModal").modal("hide");
                    Core.refreshTable("#table");
                }
                layer.msg("操作成功");
            }
        });
    });

    /*选择类别的树*/
    function showCategorys(flag){
        var ztree;
        //树-初始化设置
        var treeSetting = {
            data: {
                simpleData: {
                    enable: true,
                    idKey: "id",
                    pIdKey: "parentId"
                }
            }
        };
        Core.postAjax('/category/list',null,function (data) {
            var topCategorys = {
                name:"顶层分类",
                id:null,
                parentId:null,
                type:0
            }
            data.unshift(topCategorys);
            $.each(data,function (i, item) {
                item.open=true;
            })
            ztree=$.fn.zTree.init($("#categoryTree"), treeSetting, data);
            layer.open({
                type: 1,
                offset: '50px',
                skin: 'layui-layer-molv',
                title: "选择分类",
                area: ['300px', '450px'],
                /* shade: 0,
                 shadeClose: false,*/
                content: jQuery("#categoryLayer"),
                btn: ['确定', '取消'],
                btn1: function (index) {
                    var node = ztree.getSelectedNodes();
                    if(node.length==0){
                        layer.msg("请选择一个类别！",function(){});
                        return;
                    }
                    if(flag==1){
                        //选择上级
                        $("#categoryId_edit").val(node[0].id);
                        $("#categoryName_edit").val(node[0].name);
                    }
                    layer.close(index);
                }
            });
        });
    }

</script>
